home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
barmenu.zip
/
MENUUNIT.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1991-09-13
|
4KB
|
167 lines
UNIT MenuUnit;
Interface
USES CRT;
CONST MaxMsgLen = 32;
TYPE
MessageString = String[MaxMsgLen];
EntryPointer = ^EntryType;
EntryType = Object
Prev, Next : EntryPointer;
XCor, YCor, ChoiceNo: Integer;
Message : MessageString;
Constructor Init(ipr, inx: EntryPointer;
ix, iy, ic: Integer; im: MessageString);
Procedure Draw(Selected: Boolean);
Function GetChoice: Integer;
END;
BBMenu = Object
XCor, YCor, Wid, Choices: Integer;
FirstEntry, CurEntry : EntryPointer;
Constructor Init(ix, iy, iw: Integer);
Destructor Done;
Procedure AddPrompt(im: MessageString);
Procedure Draw;
Function GetChoice: Integer;
END;
IMPLEMENTATION
Constructor BBMenu.Init(ix, iy, iw: Integer);
BEGIN
XCor:= ix;
YCor:= iy;
Wid:= iw;
IF Wid > MaxMsgLen THEN Wid:= MaxMsgLen;
IF XCor + Wid > 80 THEN Wid:= 80 - XCor;
FirstEntry:= NIL;
Choices:= 0;
END;
Destructor BBMenu.Done;
BEGIN
IF FIrstEntry <> NIL THEN
BEGIN
FirstEntry^.Prev^.Next:= NIL;
REPEAT
CurEntry:= FirstEntry;
FirstEntry:= FirstEntry^.Next;
Dispose(CurEntry);
UNTIL FirstEntry = NIL;
END;
END;
Procedure BBMenu.AddPrompt(im: MessageString);
VAR EP: EntryPointer;
BEGIN
INC(Choices);
FillChar(im[Length(im) + 1], Wid - Length(im), ' ' );
Im[0]:= Char(Wid);
IF FirstEntry = NIL THEN
BEGIN
FirstEntry:= NEW(EntryPointer, INIT(NIL,
NIL, XCor, YCor + Choices - 1,
Choices, im));
FirstEntry^.Next:= FirstEntry;
FirstEntry^.Prev:= FirstEntry;
END
ELSE
BEGIN
EP:= NEW( EntryPointer, Init(FirstEntry^.Prev,
FirstEntry, XCor, YCor + Choices - 1,
Choices, Im));
FirstEntry^.Prev^.Next:= EP;
FirstEntry^.Prev:= EP;
END;
END;
Procedure BBMenu.Draw;
VAR ro, Co: BYTE;
BEGIN
GotoXY(XCor - 1, YCor - 1); Write(#218);
FOR Co:= 1 TO Wid DO Write(#196); Write(#191);
FOR Ro:= YCor TO YCor + Choices - 1 DO
BEGIN
GotoXY(XCor - 1, ro); Write(#179);
GotoXY(XCor + Wid, ro); Write(#179);
END;
GotoXY(XCor - 1, YCor + Choices); Write(#192);
FOR Co:= 1 to Wid DO Write(#196); Write(#217);
CurEntry:= FirstEntry;
REPEAT
CurEntry^.Draw(False);
CurEntry:= CurEntry^.Next;
UNTIL CurEntry = FirstEntry;
END;
CONST
KEnter = $000D; KEsc = $001B;
KHome = $4700; KEnd = $4F00;
KLeft = $4B00; KRight = $4D00;
KDown = $5000; KUp = $4800;
Function BBMenu.GetChoice: Integer;
VAR
SaveX, SaveY: Integer;
Finished: Boolean;
InChar: Char;
Inword: Word;
BEGIN
SaveX:= WhereX;
SaveY:= WhereY;
Draw;
Finished:= False;
REPEAT
CurEntry^.Draw(True);
InChar:= ReadKey;
IF (InChar = #0) AND KeyPressed THEN
BEGIN
InChar:= ReadKey;
InWord:= Word(InChar) SHL 8;
END
ELSE InWord:= ORD(InChar);
CurEntry^.Draw(False);
CASE InWord OF
KLeft, KUp : CurEntry:= CurEntry^.Prev;
KRight, KDown: CurEntry:= CurEntry^.Next;
KHome : CurEntry:= FirstEntry;
KEnd : CurEntry:= FirstEntry^.Prev;
KEsc : BEGIN
Finished:= True;
GetChoice:= 0;
END;
KEnter : BEGIN
Finished:= True;
GetChoice:= CurEntry^.GetChoice;
END;
END;
UNTIL Finished;
GotoXY( SaveX, SaveY);
END;
CONSTRUCTOR EntryType.Init(ipr, inx: EntryPointer;
ix, iy, ic: Integer;
im: MessageString);
BEGIN
Prev := ipr;
Next := inx;
XCor := ix;
YCor := iy;
ChoiceNo:= ic;
Message := im;
END;
Procedure EntryType.Draw(Selected: Boolean);
BEGIN
IF Selected THEN TextAttr:= $70
ELSE TextAttr:= $07;
GotoXY(XCor, YCor);
Write(Message);
END;
Function EntryType.GetChoice: Integer;
Begin
GetChoice:= ChoiceNo;
END;
END.